//
//  LLNewsViewController.m
//  LoveLove
//
//  Created by wkf on 2019/4/2.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "LLNewsViewController.h"
#import "LLNotice1TableViewCell.h"
#import "LLNotice2TableViewCell.h"
#import "LLTwoLabelButton.h"
#import "LLDirectMessagesTableViewCell.h"

@interface LLNewsViewController ()<UINavigationControllerDelegate>
@property (strong, nonatomic) LLButton *noticeButton;//通知按钮
@property (strong, nonatomic) LLTwoLabelButton *directMessagesButton;//私信按钮
@property (assign, nonatomic) NSInteger type;
@end

@implementation LLNewsViewController

- (void)viewWillAppear:(BOOL)animated {
    [[IQKeyboardManager sharedManager] setEnable:NO];
    [super viewWillAppear:animated];
    [SVProgressHUD dismiss];
    self.navigationController.delegate = self;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    //TODO: 页面Disappear 启用
    [[IQKeyboardManager sharedManager] setEnable:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleView];
    self.type = 1;
    self.titleLabel.hidden = YES;
    self.rightButton.hidden = YES;
    
    self.noticeButton = [LLInitBaseViewTool buttonWithTitle:@"通知" image:nil titleColor:LLColor(218, 13, 13) font:18];
    self.noticeButton.frame = CGRectMake(LLScreenWidth/2-85, self.navH-33, 80, 18);
    [self.noticeButton addTarget:self action:@selector(didSelectNews:) forControlEvents:UIControlEventTouchUpInside];
    self.noticeButton.tag = 1;
    [self.titleView addSubview:self.noticeButton];
    
    self.directMessagesButton = [LLTwoLabelButton new];
    self.directMessagesButton.nameLabel.text = @"私信";
    self.directMessagesButton.numberLabel.text = @"4";
    self.directMessagesButton.numberLabel.backgroundColor = LLColor(218, 13, 13);
    self.directMessagesButton.numberLabel.layer.masksToBounds = YES;
    self.directMessagesButton.nameLabel.frame = CGRectMake(0, 0, 40, 18);
    self.directMessagesButton.numberLabel.frame = CGRectMake(45, 0, 18, 18);
    self.directMessagesButton.numberLabel.layer.cornerRadius = 9;
    self.directMessagesButton.frame = CGRectMake(LLScreenWidth/2+5, self.navH-33, 80, 18);
    [self.directMessagesButton addTarget:self action:@selector(didSelectNews:) forControlEvents:UIControlEventTouchUpInside];
    self.directMessagesButton.tag = 2;
    [self.titleView addSubview:self.directMessagesButton];
    
    // Do any additional setup after loading the view.
}

#pragma mark - 显示视图操作方法
- (void)configTableView {
    self.needRefresh = NO;
    [super configTableView];
    self.tableView.backgroundColor = LLColorRGB(255);
    self.tableView.top = self.navH;
    self.tableView.mj_h = LLScreenHeight-self.navH;
    [self.tableView registerCellByClassName:@"LLNotice1TableViewCell"];
    [self.tableView registerCellByClassName:@"LLNotice2TableViewCell"];
    [self.tableView registerCellByClassName:@"LLDirectMessagesTableViewCell"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    if (self.models.count) {
//        [self hideNoDataView];
//        return self.models.count;
//    }
//    [self showNoDataView:@"矢量智能对象" title:@"还没有相关的订单呢"];
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == 1) {
        LLNotice1TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LLNotice1TableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        
//        LLNotice2TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LLNotice2TableViewCell"];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    } else {
        LLDirectMessagesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LLDirectMessagesTableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        return cell;
    }
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.type == 1) {
        return 93;
        
//        LLNotice2TableViewCell * cell = (LLNotice2TableViewCell *)[tableView.dataSource tableView:self.tableView cellForRowAtIndexPath:indexPath];
//        return [cell cellHeight];
    } else {
        return 56;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.0000001;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.0000001;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)didSelectNews:(LLButton *)button{
    self.type = button.tag;
    if (button.tag == 1) {
        [self.noticeButton setTitleColor:LLColor(218, 13, 13) forState:0];
        self.directMessagesButton.nameLabel.textColor = LLColorRGB(127);
    } else {
        self.directMessagesButton.nameLabel.textColor = LLColor(218, 13, 13);
        [self.noticeButton setTitleColor:LLColorRGB(127) forState:0];
    }
    [self.tableView reloadData];
}

#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

- (void)dealloc {
    self.navigationController.delegate = nil;
    [LLNotificationCenter removeObserver:self];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
